#ifndef __PROJECT_H__
#define __PROJECT_H__

// Qt Includes
#include <QObject>
#include <QStringList>
#include <QSet>
#include <QProcess>
#include <QMap>

// Local Declarations
class CPluginProcess;
class CResults;
class CSettings;

// ******************************************************************
// CProject
// ******************************************************************
class CProject : public QObject
{
	Q_OBJECT

public:
// Construction & Destruction
	CProject(const QString &strSettingsPath,
		const QString &strSourcePath = QString(), // By default, the source-path is configured in the settings file.
		QObject *pParent = NULL);
	~CProject();

// Enums
	enum ProjectState
	{
		PROJECT_STATE_INIT,
		PROJECT_STATE_IDLE,
		PROJECT_STATE_RUNNING,
		PROJECT_STATE_PAUSED
	};

// Member Accessors
	const QString& getSourcePath() const { return m_strSourcePath; }
	const QString& getResultsPath() const { return m_strResultsPath; }
	const CSettings* getSettings() const { return m_pSettings; }
	ProjectState getProjectState() const { return m_eProjectState; }
	const QString& getErrorHint() const { return m_strErrorHint; }

public slots:
	void runProject();
	void stopProject();
	void pauseProject();

	void tickProject();

signals:
	void stateChanged(ProjectState eProjectState);

private slots:
	void pluginFinished(int nExitCode,
		QProcess::ExitStatus eExitStatus);

private:
// Enums
	enum ProjectRequest
	{
		PROJECT_REQUEST_START = 0x01,
		PROJECT_REQUEST_STOP = 0x02,
		PROJECT_REQUEST_PAUSE = 0x04
	};

// Member Functions
	bool loadSettings(const QString &strSettingsPath);
	bool loadPluginNames(); // Compiles a list of plugin-names to be run by the project.

	void setState(ProjectState eProjectState);
	void makeRequest(quint8 nRequest);
	bool isRequestActive(quint8 nRequest,
		bool bClear = false);

	void addResult(const QString &strOutput);

// Member Variables
	QString m_strSettingsPath;
	QString m_strSourcePath, m_strResultsPath;
	QStringList m_slPlugins;
	CSettings *m_pSettings;
	ProjectState m_eProjectState;
	quint8 m_nRequest;
	QString m_strErrorHint;
	QSet<CPluginProcess*> m_setRunningPlugins;
	QStringList m_slFileList;
	CResults *m_pResults;
	QMap<QString, quint32> m_mapPluginID;
	QMap<QString, quint32> m_mapFileNameID;
};

#endif // #ifndef __PROJECT_H__
